#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int numSquares(int n) {
        vector<int> w(101);
        for (int i = 1; i <= 100; i++) w[i] = i * i;
        vector<int> dp(n + 1, 10000);
        dp[0] = 0;
        for (int i = 1; i <= 100; i++)
            for (int j = w[i]; j <= n; j++)
                dp[j] = min(dp[j], dp[j - w[i]] + 1);
        return dp[n];
    }
};